import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tc.utils.HttpClientUtil;
import com.xiaoleilu.hutool.util.HashUtil;
import jetbrick.util.codec.HexUtils;
import jetbrick.util.codec.MD5Utils;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.StringEscapeUtils;
import org.bouncycastle.jcajce.provider.digest.MD5;
import org.junit.Test;

import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

@Slf4j
public class test6 {
    //企业股权穿透接口keyWord=keyWord
    String stockAnalysisDataUrl="http://i.yjapi.com/ECICompanyMap/GetStockAnalysisData?key=9f2c342e074744cfabfbd40996adb4c1";
    //受益人穿透接口companyName=北京小桔科技有限公司&percent=25
    String beneficiaryUrl="http://i.yjapi.com/Beneficiary/GetBeneficiary?key=9f2c342e074744cfabfbd40996adb4c1";
    //企业工商数据查询keyword=北京小桔科技有限公司
    String betails="http://i.yjapi.com/ECIV4/GetDetailsByName?key=9f2c342e074744cfabfbd40996adb4c1";

    @Test
    public void demo1() throws Exception{
        Map map=new HashMap();
        map.put("keyWord","唯品会");
        String get = HttpClientUtil.Get(stockAnalysisDataUrl, map);
        log.info(get);
    }

    @Test
    public void demo2() throws Exception{
        Map map=new HashMap();
        map.put("companyName","北京小桔科技有限公司");
        map.put("percent","25");
        String get = HttpClientUtil.Get(beneficiaryUrl, map);
        log.info(get);
    }

    @Test
    public void demo3() throws Exception{
        Map map=new HashMap();
        map.put("keyword","北京小桔科技有限公司");
        String get = HttpClientUtil.Get(betails, map);
        log.info(get);
    }


    @Test
    public void demo4() throws Exception{
        String encode = URLEncoder.encode("唯品会(中国)有限公司","UTF-8");
        log.info(encode);
        String decode = URLDecoder.decode("%282123132%29%E5%93%88%E5%93%88%25%3C%24%24%3E%25%25","UTF-8");
        log.info(decode);
        //String s = StringEscapeUtils.unescapeHtml(encode);
        log.info("");
    }

    @Test
    public void demo5() throws Exception{

       // log.info(StringEscapeUtils.escapeHtml("(abc)"));

       // log.info(StringEscapeUtils.unescapeHtml("&#40;2123132&#41;哈哈%&lt;$$&gt;%%"));

    }

    @Test
    public void demo6() throws Exception{
        Map map = JSON.parseObject("{\"status\":\"1\",\"returnValue\":{\"batNo\":\"2018120420500139\",\"unitName\":\"上海品众商业保理有限公司\",\"subOrgan\":\"风控部\",\"queryUserID\":\"pzwsquery6\",\"queryCount\":\"1\",\"receiveTime\":\"20181204 20:49:12\",\"cisReport\":[{\"buildEndTime\":\"2018-12-04 20:49:12\",\"hasSystemError\":\"true\",\"isFrozen\":\"false\",\"queryConditions\":[{\"name\":\"corpName\",\"caption\":\"企业名称\",\"value\":\"北京爱奇艺科技有限公司1\"}],\"queryReasonID\":\"101\",\"reportID\":\"2018120420500139\",\"subReportTypes\":\"22117\",\"subReportTypesShortCaption\":\"1、企业经营异常\",\"treatResult\":\"0\",\"corpManageAbnormalInfo\":{\"subReportType\":\"22117\",\"subReportTypeCost\":\"22117\",\"treatResult\":\"3\",\"treatErrorCode\":\"202\",\"errorMessage\":\"系统错误\"}}]}}", Map.class);

        System.out.println(((JSONObject)map.get("returnValue")));

        System.out.println((String)map.get("abc"));

    }

    @Test
    public void demo7() throws Exception{
        byte[] md5 = MD5Utils.md5("哈哈dddd");
        int i=0;
        int j=md5.length-1;
        byte[] md5new =new byte[md5.length/2];
        while (i<j){
            md5new[i] =  (byte)(md5[i] ^ md5[j]);
            System.out.println((byte)(md5[i] ^ md5[j]));
            i++;j--;
        }
        System.out.println(HexUtils.encodeHexString(md5));
        System.out.println(HexUtils.encodeHexString(md5).length());
        System.out.println(HexUtils.encodeHexString(md5new));
        System.out.println(HexUtils.encodeHexString(md5new).length());
    }


    @Test
    public void demo8() throws Exception{
        String appId=null;
        String merchantId="MU10004455111";
        if(merchantId.length()>10){
            log.info("商户号大于10位数,不允许报备");
        }
        log.info(generateMerchantRemark(appId,merchantId));
        //log.info(appId+merchantId);
    }

    private String generateMerchantRemark(String appId,String merchantRemark){
        if(appId==null){
            appId="";
        }
        if(appId.length()>10){
            appId=appId.substring(appId.length()-10,appId.length());
        }
        return merchantRemark+appId;
    }


}
//http://i.yjapi.com/ECICompanyMap/GetStockAnalysisData?key=9f2c342e074744cfabfbd40996adb4c1&companyName=唯品会&percent=25
